package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ITDeclarationMatchingService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.TDeclarationMatchingCreateValidate;
import com.mdd.admin.validate.TDeclarationMatchingUpdateValidate;
import com.mdd.admin.validate.TDeclarationMatchingSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.TDeclarationMatchingListedVo;
import com.mdd.admin.vo.TDeclarationMatchingDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/matching")
@Api(tags = "临时存项目政策的申报条件，公司哪些匹配或不匹配管理")
public class TDeclarationMatchingController {

    @Resource
    ITDeclarationMatchingService iTDeclarationMatchingService;

    @GetMapping("/list")
    @ApiOperation(value="临时存项目政策的申报条件，公司哪些匹配或不匹配列表")
    public AjaxResult<PageResult<TDeclarationMatchingListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated TDeclarationMatchingSearchValidate searchValidate) {
        PageResult<TDeclarationMatchingListedVo> list = iTDeclarationMatchingService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="临时存项目政策的申报条件，公司哪些匹配或不匹配详情")
    public AjaxResult<TDeclarationMatchingDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TDeclarationMatchingDetailVo detail = iTDeclarationMatchingService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "临时存项目政策的申报条件，公司哪些匹配或不匹配新增")
    @PostMapping("/add")
    @ApiOperation(value="临时存项目政策的申报条件，公司哪些匹配或不匹配新增")
    public AjaxResult<Object> add(@Validated @RequestBody TDeclarationMatchingCreateValidate createValidate) {
        iTDeclarationMatchingService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "临时存项目政策的申报条件，公司哪些匹配或不匹配编辑")
    @PostMapping("/edit")
    @ApiOperation(value="临时存项目政策的申报条件，公司哪些匹配或不匹配编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody TDeclarationMatchingUpdateValidate updateValidate) {
        iTDeclarationMatchingService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "临时存项目政策的申报条件，公司哪些匹配或不匹配删除")
    @PostMapping("/del")
    @ApiOperation(value="临时存项目政策的申报条件，公司哪些匹配或不匹配删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iTDeclarationMatchingService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
